import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { TableComponent } from './table.component';
import { environment } from '../../../../environments/environment';
import { LocalStorage } from '@core/local.storage';

@Component({
    selector: 'app-petitionview',
    templateUrl: './petitionView.component.html',
    styleUrls: ['./petitionView.component.less']
})

export class PetitionViewComponent implements OnInit {
    @ViewChild('tcp', { static: true }) tcp: TableComponent;
    searchParam: any = {};
    apiUrl: any = {};
    headData = [];
    plainData = [];
    tempData = [];
    operaList: any = [
        { addModal: false },
        { editModal: false }
    ];
    userId = JSON.parse(this.ls.get('loginInfo')).VC_NUMBER;
    typeName = window.location.href.split('/')[window.location.href.split('/').length - 1];

    constructor(
        public ls: LocalStorage,
        public http: _HttpClient
    ) { }

    ngOnInit() {
        this.headData = [
            { "name": "举报人姓名", "width": "6%" },
            { "name": "举报人性别", "width": "6%" },
            { "name": "举报人联系方式", "width": "7%" },
            { "name": "被举报人单位/部门", "width": "8%" },
            { "name": "被反映人姓名", "width": "6%" },

            { "name": "被反映人性别", "width": "6%" },
            { "name": "被反映人单位", "width": "6%" },
            { "name": "被反映人级别", "width": "6%" },
            { "name": "被反映人职务", "width": "6%" },
            { "name": "反应主要问题", "width": "" },

            { "name": "反应时间", "width": "9%" },
            { "name": "处理状态", "width": "5%" },
            { "name": "处理内容", "width": "8%" },
            { "name": "操作", "width": "5%" }
        ];
        this.plainData = [
            "informantName", "informantSexFormat", "informantPhone", "informantCompany", "reflectionPersonName",
            "reflectionPersionSexFormat", "reflectionPersonCompany", "reflectionPersonLevelFormat", "reflectionPersonDuties", "reflectProblem",
            "reflectTime", "statusFormat", "processContent", "opera"
        ];
        this.apiUrl.add = environment.devscore + '/letter/add';
        this.apiUrl.edit = environment.devscore + '/letter/update';
        this.apiUrl.del = environment.devscore + '/letter/delete';
        this.loadList();
    }
    loadList() {
        this.tcp.loadList(environment.devscore + '/letter/queryLetterVisitsPage', { "type": this.typeName === 'edit' ? "user" : "", "userId": this.userId });
    }
    edit(data) {
        const tempData = this.tcp.getAllData();
        for (const item of tempData) {
            item.checked = item.id === data.id ? true : false;
        }
        this.tempData = tempData;
        this.operaList.editModal = true;
    }
    search() {
        const params: any = {};
        for (const item of Object.keys(this.searchParam)) {
            const data = this.searchParam[item];
            if (data || data === 0) {
                params[item] = data;
            }
        }
        params.type = this.typeName === 'edit' ? "user" : "";
        params.userId = this.userId;
        this.tcp.loadList(environment.devscore + '/letter/queryLetterVisitsPage', params);
    }
    modalShow(type) {
        this.tempData = this.tcp.getAllData();
        this.operaList[type] = true;
    }
    modalHide(type) {
        this.operaList[type] = false;
    }
}
